package com.lgc.demo.example;

import java.util.HashMap;
import java.util.Map;

public class MyHashMap {
    public static void main(String[] args) {
        double random = Math.random();

        Map<Integer, Integer> map = new HashMap<>();
        map.put(1,11);
        map.put(2,12);
        map.put(3,13);
        map.put(4,14);

        boolean isS = map.containsKey(3);
        int value =map.get(2);

        int[] nums = new int[4];
        nums[0]=15;
        nums[1]=2;
        nums[2]=11;
        nums[3]=7;
        int target = 9;

        MyHashMap myHashMap=new MyHashMap();
        int[] array = myHashMap.twoSum(nums,target);

        int a=0;
    }

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int complement = target - nums[i];
            if (map.containsKey(complement)) {
                return new int[] { map.get(complement), i };
            }
            map.put(nums[i], i);
        }
        throw new IllegalArgumentException("No two sum solution");
    }


}
